import time

from selenium.webdriver.common.by import By
from data_023.Page.Page import Page

class Page1(Page):
    # 点击登录
    login = (By.XPATH, '//html/body/div[1]/div/div[2]/ul/li[1]/a')

    def login_loc(self):
        self.click(self.login)

    # 输入用户名
    username_01 = (By.XPATH, '//*[@id="theForm"]/div[1]/span[2]/input')

    def username(self):
        self.send_keys(self.username_01, '17660387762')

    # 输入密码
    password_01 = (By.XPATH, '//*[@id="theForm"]/div[1]/span[2]/input')

    def password(self):
        self.send_keys(self.password_01, '123456')

    # 点击登录按钮
    dl = (By.XPATH, '//*[@id="theForm"]/div[5]/a')

    def dl_01(self):
        self.click(self.dl)

    # 断言登录成功
    login_02 = (By.XPATH, '/html/body/div[5]/div[2]/div[1]/div[2]/div[2]/ul/li[1]')

    def dy02(self):
        aa = self.find_element(self.login_02).text()
        assert '您好，17660387762 欢迎回来' in aa
        print(aa)
    # 点击秒杀
    shouye = (By.XPATH, '/html/body/div[3]/div[2]/ul/li[4]/a')
    def miaosha(self):
        self.click(self.shouye)
    # 选择并点击商品
    sp = (By.XPATH,'/html/body/div[5]/div[2]/div[2]/div[1]/ul/li[6]/div[1]/span/a/img')
    def sp_01(self):
        self.click(self.sp)
    # 断言商品详情
    xq = (By.XPATH,'//*[@id="goodsForm"]/div/div[1]/span')
    def xq01(self):
        xqs = self.find_element(self.xq).text()
        assert '音乐耳机' == xqs
        print(xqs)
    # 点击立即购买
    gm = (By.ID,'buy-cart')
    def gm_01(self):
        self.click(self.gm)
    # 选择收货地址
    dz = (By.ID,'address-55')
    def dz_01(self):
        self.click(self.dz)
    # 点击下一步
    xyb = (By.ID,'order-button')
    def xyb_01(self):
        self.click(self.xyb)
    def A3mall_002(self):
        self.open_url('http://10.59.9.14:7003/')
        self.login_loc()
        self.username()
        self.password()
        time.sleep(7)
        self.dl_01()
        self.dy02()
        self.dy02()
        self.miaosha()
        self.sp_01()
        self.xq01()
        self.gm_01()
        self.dz_01()
        self.xyb_01()

